using System.Data;
using System.Data.SqlClient;
using VanTaiProperty;
namespace VanTaiData
{
    public class clsTMDOController
    {
        private clsConnect cls = new clsConnect();
        private DataTable dt;
        #region[Get-Data]
        public DataTable BindGirdTMDO()
        {
            return cls.BindGridData("sp_TMDO");
        }
        public DataTable BindGirdTMDO_Detail_Edit(int id)
        {
            return cls.LayDuLieuParameter("sp_TMDO_Detail_Edit", "@DO_ID", id);
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertTMDO(clsTMDOProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@DO_Alias", data.DO_Alias);
            cls.AddParameter("@DO_Name", data.DO_Name);
            cls.AddParameter("@DO_Quality", data.DO_Quality);
            cls.AddParameter("@DO_Space", data.DO_Space);
            cls.AddParameter("@Unit_ID", data.Unit_ID);
            cls.AddParameter("@Unit_ID_Space", data.Unit_ID_Space);
            cls.AddParameter("@DO_Price", data.DO_Price);
            cls.AddParameter("@NetWeight", data.NetWeight);
            cls.AddParameter("@DO_Discription", data.DO_Discription);
            cls.AddParameter("@DO_Status", data.DO_Status);
            cls.ExecuteNonQuery("sp_TMDO_Insert");
            return true;
        }
        public bool UpdateTMDO(clsTMDOProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@DO_ID", data.DO_ID);
            cls.AddParameter("@DO_Alias", data.DO_Alias);
            cls.AddParameter("@DO_Name", data.DO_Name);
            cls.AddParameter("@DO_Quality", data.DO_Quality);
            cls.AddParameter("@DO_Price", data.DO_Price);
            cls.AddParameter("@Unit_ID", data.Unit_ID);
            cls.AddParameter("@DO_Space", data.DO_Space);
            cls.AddParameter("@Unit_ID_Space", data.Unit_ID_Space);
            cls.AddParameter("@NetWeight", data.NetWeight);
            cls.AddParameter("@DO_Discription", data.DO_Discription);
            cls.AddParameter("@DO_Status", data.DO_Status);
            cls.ExecuteNonQuery("sp_TMDO_Update");
            return true;
        }
        public bool UpdateTM_DO_Quality(clsTMDOProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@DO_ID", data.DO_ID);
            cls.AddParameter("@DO_Quality", data.DO_Quality);
            cls.ExecuteNonQuery("sp_TMDO_Update_Price_Quality");
            return true;
        }
        public bool DeleteTMDO(int id)
        {
            cls.Delete("sp_TMDO_Delete", "@DO_ID", id);
            return true;
        }
        public bool TMDO_Check_Delete_TMDO_ENTRY(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMDO_Check_Delete_TMDO_ENTRY", "@ID", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMDO_Check_Delete_TMDO_BILL(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMDO_Check_Delete_TMDO_BILL", "@ID", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        #endregion

        #region[Search]
        public DataTable Search(string keywords)
        {
            return cls.Search("sp_TMDO_Search", "@KEYWORDS", keywords);
        }
        #endregion
    }
}